var express = require('express')
//引入cookie
var session = require('express-session')

const MongoStore = require('connect-mongo')(session);

var app = express()
//使用cookie
app.use(session({
    secret: 'keyboard cat',
    resave: false,
    saveUninitialized: true,
    cookie: {
        // secure: true
        maxAge: 60000
    },/*需要https才能访问*/
    rolling: true,
    store: new MongoStore({
        url: 'mongodb://127.0.0.1/users',// 数据库地址
        touchAfter: 24 * 3600 // time period in seconds
    })
}))

app.get('/',function (req, res) {
    console.log(req.session.userInfo)
    res.send('你好nodejs')
})

app.get('/set', function (req, res) {
    //参数一：参数名  参数二：参数值  参数三：cookie的配置信息
    req.session.userInfo = 'zhangsan'
    res.send('添加session')

})

app.listen(3001)